package com.homework.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.homework.dao.UserDao;

public class LoginServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		//获取信息
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		//连接数据库查询验证user的存在
		UserDao userDao = new UserDao();
		boolean isUser = userDao.isUser(username,password);
		if(isUser){
			//跳转管理界面
			req.getRequestDispatcher("manage.jsp").forward(req, resp);
		}else{
			//调转失败页面
			resp.sendRedirect("default.jsp");
		}
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req, resp);
	}
}
